<!--
 * @Descripttion: 
 * @version: v1.0
 * @Author: baidongsheng
 * @Date: 2021-11-27 10:23:06
 * @LastEditors: baidongsheng
 * @LastEditTime: 2021-11-30 10:47:07
-->
<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <div v-show="!switchHeader" class="head-wrap">
        <Header />
      </div>
      <div v-show="switchHeader">
      </div>
      <router-view :class="{ 'container' : !this.$route.fullPath.includes('pre-view') }" />
    </div>
  </a-config-provider>
</template>

<script lang="ts">
// eslint-disable-next-line
import { Component, Vue, Watch } from 'vue-property-decorator';
// eslint-disable-next-line
import { Route } from 'vue-router';
// eslint-disable-next-line
import { ConfigProvider } from '@h3/antd-vue';

import Header from './components/global/header/index.vue';

import OAuthApi from '@/apis/oauth';
import app from '@cloudpivot/common/src/constants/globalApplication';

import zhCN from '@h3/antd-vue/lib/locale-provider/zh_CN';
import enUS from '@h3/antd-vue/lib/locale-provider/en_US';
import 'moment/locale/zh-cn';
import { themesApi } from "@cloudpivot/api";
import getDownloadUrlNew from '@cloudpivot/common/src/utils/getDownloadUrlNew';

const env = (window as any).config;

@Component({
  name: 'apps',
  components: {
    Header,
    AConfigProvider: ConfigProvider,
  },
})
export default class Apps extends Vue {
  created(){
    themesApi.getThemesInfo().then((res:any) => {
      this.$store.commit('setThemsConfig', res)
      if(res.icon){
        this.changeFavicon(this.getIcon(res.icon))
      }

      if(res.name && document.title.indexOf('云枢-') !== -1){
        document.title = document.title.replace('云枢-', res.name + '-')
      }
    })
  }
  
  // 修改浏览器标签页上的小图标
  changeFavicon(link){
    if(!link){
      return
    }
    let $favicon:any = document.querySelector('link[rel="icon"]');
    if ($favicon !== null) {
        $favicon.href = link;
    } else {
        $favicon = document.createElement("link");
        $favicon.rel = "icon";
        $favicon.href = link;
        // @ts-ignore
        document.head.appendChild($favicon);
    }
  }

  getIcon(refId: string){
    return refId ? this.getDownloadUrlByRefId(refId) : ''
  }
  getDownloadUrlByRefId(refId: string): string {
    return getDownloadUrlNew.getImageUrl(refId, 'logo');
  }


  //@Getter('getAntLocale') locale!: string;
  switchHeader = false;
  get locale() {
    switch (this.$i18n.locale) {
      case 'en':
        return enUS;
      case 'zh':
      default:
        return zhCN;
    }
  }

  async mounted() {
    // 获取配置文件
    const config = await OAuthApi.getSystemConfig();
    if (config) {
      this.$store.commit('setConfig', config);
    }
    app.errorManager.getErrorCode();
  }

  @Watch('$route')
  routeChange(n: Route, o: Route) {
    // eslint-disable-next-line
    if(n.fullPath.includes('print-template') || n.fullPath.includes('pre-view'))
      this.switchHeader = true;
    else
      this.switchHeader = false;
  }
}
</script>

<style>
 .ant-calendar-range-middle{
   padding: 0!important;
 }
</style>
